<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true">
      <el-form-item label="战线单位" >
        <el-select
          v-model="queryParams.depId"
          placeholder="请选择"
          @change="search"
          clearable
          size="small"
        >
          <el-option
            v-for="dict in statusOptions"
            :key="dict.deptId"
            :label="dict.deptName"
            :value="dict.deptId"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <!--        <el-button type="primary" icon="el-icon-search" size="mini" @click="search" style="margin-left: 10px">查询</el-button>-->
        <el-button type="primary" icon="el-icon-check" size="mini" @click="plPass" style="margin-left: 10px">批量通过</el-button>
        <el-button type="danger" icon="el-icon-close" size="mini" @click="plReject" style="margin-left: 10px">批量驳回</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="roleList" stripe border
     @selection-change="handleSelectionChange" >
      <el-table-column align="center" type="selection" width="80"></el-table-column>
      <el-table-column align="center" type="index" label="序号"  width="55"  />
      <el-table-column align="center" label="申请名称"   property="pickName" :show-overflow-tooltip="true"  ></el-table-column>
      <el-table-column align="center" label="费用项目名称"   property="moneySourceName" :show-overflow-tooltip="true"  ></el-table-column>
      <el-table-column align="center" label="科室" property="depName" :show-overflow-tooltip="true" ></el-table-column>
      <el-table-column align="center" label="金额/元"  property="totalAmount" ></el-table-column>
      <el-table-column align="center" label="计划号" property="planNum" :show-overflow-tooltip="true" v-if="false" ></el-table-column>
      <el-table-column
        label="操作"
        align="center"
        width="300">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="success"
            icon="el-icon-s-unfold"
            @click="xingqing(scope.row)">详情</el-button>
          <el-button
            size="mini"
            type="danger"
            icon="el-icon-close"
            @click="handleEdit(scope.$index, scope.row)">驳回</el-button>
          <el-button
            size="mini"
            type="primary"
            icon="el-icon-check"
            @click="handleDelete(scope.$index, scope.row)">通过</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="search"
    />



  </div>
</template>

<script>
  import request from '@/utils/request'
  import { listRole, getRole, delRole, addRole, updateRole, exportRole, dataScope, changeRoleStatus } from "@/api/system/role";

  export default {
    name: "Role",
    components:{
      // xqjhDialog,
    },
    data() {
      return {
         //记录分页数据
        localPage:undefined,
        localSize:undefined,
        //选中的物料id
        wlID:[],
        xqjhShow:false,
        xqjhStr:{},
        // 遮罩层
        loading: false,
        // 总条数
        total: 0,
        // 角色表格数据
        roleList: [],
        // 日期范围
        dateRange: [],
        //资金来源
        zjlyList:[
          { value: '1',label: '来源1'},
          { value: '2',label: '来源2'},
        ],
        //计划状态
        jhztList:[
          { value: '1',label: '草稿箱'},
          { value: '2',label: '已提交'},
        ],
        // 状态数据字典
        statusOptions: [],
        
        // 数据范围选项
        dataScopeOptions: [
          {
            value: "1",
            label: "全部数据权限"
          },
          {
            value: "2",
            label: "自定数据权限"
          },
          {
            value: "3",
            label: "本部门数据权限"
          },
          {
            value: "4",
            label: "本部门及以下数据权限"
          },
          {
            value: "5",
            label: "仅本人数据权限"
          }
        ],
        // 菜单列表
        menuOptions: [],
        // 部门列表
        deptOptions: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          depId:0,
        },
        // 表单参数
        form: {},
        defaultProps: {
          children: "children",
          label: "label"
        },
      };
    },
    created() {
      this.getZhanxin()
      this.jlPage()
      this.search()

    },
    methods: {
      //获取站线数据
      getZhanxin:function(){
        request({
          url: '/system/dept/listFront',
          method: 'get',
        }).then(response => {
          this.statusOptions = response.data
          this.statusOptions.unshift(
            {deptId:0,deptName:'全部'}
          )
        });
      },
      //记录页码数据
      jlPage () {
        this.localSize = this.$route.query.size
      this.localPage = this.$route.query.page
      console.log(this.$route.query.page)
      if(this.localPage!==undefined) {
          this.queryParams.pageNum = this.localPage
          console.log(111)
      }
      if(this.localSize!==undefined) {
        this.queryParams.pageSize = this.localSize
      }
      },
      //批量选择的物料信息
      handleSelectionChange (row) {
        console.log(row)
         this.xzWlmessage = row
         console.log(this.xzWlid())
      },
      //获取选中的物料id
      xzWlid () {
        this.wlID=[],
        this.xzWlmessage.forEach(item =>{
          this.wlID.push(item.id)
          console.log(this.wlID)
        })
        return this.wlID
      },
      //批量通过按钮
      plPass () {
        console.log('批量审批')
        this.$confirm('确认通过?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
           console.log('通过')
          //
          var idnum = this.xzWlid()
          this.plsaveBtn(idnum,6)
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消通过'
          });
        });
      },
      //批量驳回
      plReject () {
        this.$confirm('确认驳回?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          console.log('驳回')
          var idnum = this.xzWlid()
          this.plsaveBtn(idnum,5)
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消驳回'
          });
        });
      },
      plsaveBtn:function(row,num){
        var plobj={}
        plobj.ids = row
        plobj.auditSteps = num
        console.log(plobj)
        request({
          url: '/system/demandPlan/stepsList',
          method: 'put',
          data: plobj
        }).then(response => {
          if(response.code=='200'){
            this.$message({
              type: 'success',
              message: '操作成功!'
            });
          }
          this.search();
        });
      },
      //监听
      jianting:function(row){
        console.log('row',row)

      },
      //新增回调函数
      xujhBack:function(row){
        console.log('返回数据',row)
        this.xqjhShow = false
      },
      //更多操作按钮
      handleCommand:function(command){
        // this.$message('click on item ' + command);
        if(command=='1'){
          var pp={
            title:'新增需求计划',
          }
          this.xqjhStr = pp
          this.xqjhShow = true
        }
      },
      //查询
      search:function(){
         this.localPage = this.queryParams.pageNum
        this.localSize = this.queryParams.pageSize
        this.loading = true
        request({
          url: '/system/demandPlan/listByLeader',
          method: 'get',
          params:this.queryParams
        }).then(response => {
          this.loading = false
          this.roleList = response.rows
          console.log(this.roleList)
          this.total = response.total
        });
      },
      //驳回
      handleEdit:function (index,row) {
        this.$confirm('确认驳回?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.saveBtn(row,5)
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消驳回'
          });
        });
      },
      saveBtn:function(row,num){
        var obj={}
        obj.id = row.id
        obj.auditSteps = num
        request({
          url: '/system/demandPlan/steps',
          method: 'put',
          data: obj
        }).then(response => {
          if(response.code=='200'){
            this.$message({
              type: 'success',
              message: '操作成功!'
            });
          }
          this.search();
        });
      },
      //通过
      handleDelete:function (index,row) {
        this.$confirm('确认通过?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.saveBtn(row,6)
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消通过'
          });
        });
      },
      //详情点击
      xingqing:function (row) {
        console.log(row)
        this.$router.push({path:'/material/kclzspXQ',query:{data:row,page:this.localPage,size:this.localSize}});
      },

    }
  };
</script>
